#region File Description
//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
#endregion

namespace JeremiXnaGame
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class OptionsMenuScreen : MenuScreen
    {
        #region Fields

        MenuEntry ScreenResolutionMenuEntry;
        MenuEntry QualityMenuEntry;
        MenuEntry fullscreenMenuEntry;
        MenuEntry numberMenuEntry;

        enum Quality
        {
            Low,
            Mid,
            High,
        }

        static Quality CurrentQuality = Quality.Mid;

        static string[] languages = { "C#", "French", "Deoxyribonucleic acid" };
        static int currentLanguage = 0;

        static bool fullscreen = true;

        static int number = 23;

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base("Options")
        {
            // Create our menu entries.
            ScreenResolutionMenuEntry = new MenuEntry(string.Empty);
            QualityMenuEntry = new MenuEntry(string.Empty);
            fullscreenMenuEntry = new MenuEntry(string.Empty);
            numberMenuEntry = new MenuEntry(string.Empty);

            SetMenuEntryText();

            MenuEntry backMenuEntry = new MenuEntry("Cancel");
            MenuEntry applyMenuEntry = new MenuEntry("Apply");

            // Hook up menu event handlers.
            ScreenResolutionMenuEntry.Selected += ScreenResolutionMenuEntrySelected;
            QualityMenuEntry.Selected += QualityMenuEntrySelected;
            fullscreenMenuEntry.Selected += fullscreenMenuEntrySelected;
            numberMenuEntry.Selected += numberMenuEntrySelected;
            backMenuEntry.Selected += OnCancel;
            applyMenuEntry.Selected += ApplySettings;

            // Add entries to the menu.
            MenuEntries.Add(ScreenResolutionMenuEntry);
            MenuEntries.Add(QualityMenuEntry);
            MenuEntries.Add(fullscreenMenuEntry);
            MenuEntries.Add(numberMenuEntry);
            MenuEntries.Add(backMenuEntry);
            MenuEntries.Add(applyMenuEntry);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        void SetMenuEntryText()
        {
            ScreenResolutionMenuEntry.Text = "Texture Quality: " + CurrentQuality;
            QualityMenuEntry.Text = "Screen Resulution: " + languages[currentLanguage];
            fullscreenMenuEntry.Text = "Fullscreen: " + (fullscreen ? "on" : "off");
            numberMenuEntry.Text = "test1: " + number;
        }


        #endregion

        #region Handle Input


        /// <summary>
        /// Event handler for when the Ungulate menu entry is selected.
        /// </summary>
        void ScreenResolutionMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            CurrentQuality++;

            if (CurrentQuality > Quality.High)
                CurrentQuality = 0;

            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the Language menu entry is selected.
        /// </summary>
        void QualityMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            currentLanguage = (currentLanguage + 1) % languages.Length;

            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the fullscreen menu entry is selected.
        /// </summary>
        void fullscreenMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            fullscreen = !fullscreen;

            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the number menu entry is selected.
        /// </summary>
        void numberMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            number++;

            SetMenuEntryText();
        }

        void ApplySettings(object sender, PlayerIndexEventArgs e)
        {
            JeremiGame.Singleton.ChangeResolution(1920, 1080);
            OnCancel(0);
        }


        #endregion
    }
}
